package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {

    private DBConnection (){

    }

    public static Connection getInstance(){
        Connection con = null;
        DBConnection db = new DBConnection();
        return db.getConnection(con);

    }

    private Connection getConnection(Connection con){
//        Connection con = null;
        String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/wechat_demo";
        String name = "root";
        String password = "xxxxxx";//这里我做了处理，请自行修改，仅供参考

        try {
            Class.forName(driver);
            System.out.println("数据库驱动加载成功");

            con = DriverManager.getConnection(url,name,password);
            System.out.println("数据库连接成功");
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }


        return con;
    }


    /*public static void main(String[] args) {
        DBConnection db = new DBConnection();
        db.getConnection();
    }*/


}
